﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Entity;
using YiSha.Util.Model;
using YiSha.Basics;
using YiSha.Model;
using YiSha.Service.TeUserManager;
using YiSha.Model.Param.TeUserManager;
using YiSha.Entity.OrganizationManage;

namespace YiSha.Areas.Core.TeUserManager.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2021-06-11 16:44
    /// 描 述：控制器类
    /// </summary>
    [Area("TeUserManager")]
    public class TeUserController :  BaseController
    {
        public TeUserService teUserService { get; set; }

        #region 视图功能
        /// <summary>
        /// 首页
        /// </summary>
        [AuthorizeFilter("teuserr:teuser:view")]
        public ActionResult TeUserIndex()
        {
            return View();
        }

        /// <summary>
        /// 添加/修改
        /// </summary>
        public ActionResult TeUserForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 获取数据列表
        /// </summary>
        [HttpGet]
        [AuthorizeFilter("teuserr:teuser:search")]
        public async Task<ActionResult> GetListJson(TeUserListParam param)
        {
            TData<List<UserEntity>> obj = await teUserService.GetList(param);
            return Json(obj);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        [HttpGet]
        [AuthorizeFilter("teuserr:teuser:search")]
        public async Task<ActionResult> GetPageListJson(TeUserListParam param, Pagination pagination)
        {
            TData<List<UserEntity>> obj = await teUserService.GetPageList(param, pagination);
            return Json(obj);
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        [HttpGet]
        public async Task<ActionResult> GetFormJson(string id)
        {
            TData<UserEntity> obj = await teUserService.GetEntity(id);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        /// <summary>
        /// 保存数据
        /// </summary>
        [HttpPost]
        [AuthorizeFilter("teuserr:teuser:add,teuserr:teuser:edit")]
        public async Task<ActionResult> SaveFormJson(UserEntity entity)
        {
            TData obj = await teUserService.SaveForm(entity);
            return Json(obj);
        }

        /// <summary>
        /// 删除数据（物理删除）
        /// </summary>
        [HttpPost]
        [AuthorizeFilter("teuserr:teuser:delete")]
        public async Task<ActionResult> DeleteFormJson(List<string> ids)
        {
            TData obj = await teUserService.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}
